package com.undsf.despot.modles;

import com.undsf.utility.Random;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Arathi on 2016/10/3.
 */
public class Monster extends Unit {
    public static final int ACTION_MODE_SEQUENCE = 0;
    public static final int ACTION_MODE_RANDOM = 1;

    public static final int RESISTANCE_ID_FIRE = 1;  // 火焰抗性
    public static final int RESISTANCE_ID_SLEEP = 2;  // 催眠抗性
    public static final int RESISTANCE_ID_SILENT = 3;  // 沉默抗性
    public static final int RESISTANCE_ID_BREATHLESS = 4;  // 气绝抗性
    public static final int RESISTANCE_ID_BLINDNESS = 5;  // 致盲抗性
    public static final int RESISTANCE_ID_AMPDMG = 6;  // 削甲抗性 amplify damage

    protected List<String> actions;
    protected int actionMode;
    protected int actionCounter;

    public Monster() {
        init();
    }

    @Override
    public void init() {
        super.init();
        actions = new ArrayList<String>();
    }

    @Override
    public Monster clone() {
        try {
            Monster instance = (Monster) super.clone();
            instance.hp = hpMax;
            instance.mp = mpMax;
        }
        catch (CloneNotSupportedException ex) {
            ex.printStackTrace();
        }
        return null;
    }

    @Override
    public Command selectCommand() {
        Command cmd = super.selectCommand();
        if (cmd.action != null) {
            return cmd;
        }

        int actionIndex = 0;
        if (actionMode == ACTION_MODE_SEQUENCE) {
            actionIndex = actionCounter % actions.size();
        }
        else {
            actionIndex = Random.GetRandomizer().nextInt(0, 8);
        }
        String action = actions.get(actionIndex);
        cmd.setAction(action);

        cmd.targets = new ArrayList<Unit>();
        switch (cmd.getTargetType()) {
            case Command.TARGET_TYPE_NONE:
                break;
            case Command.TARGET_TYPE_SELF:
                cmd.targets.add(this);
                break;
            case Command.TARGET_TYPE_ALLY_SINGLE:
                cmd.targets.add(force.selectAUnit());
                break;
            case Command.TARGET_TYPE_ALLY_ALL:
                cmd.targets.addAll(force.selectAllUnit());
                break;
            case Command.TARGET_TYPE_ENEMY_SINGLE:
                cmd.targets.add(force.getEnemies().selectAUnit());
                break;
            case Command.TARGET_TYPE_ENEMY_TEAM:
                cmd.targets.addAll(force.getEnemies().selectTeam());
                break;
            case Command.TARGET_TYPE_ENEMY_ALL:
                cmd.targets.addAll(force.getEnemies().selectAllUnit());
                break;
        }
        actionCounter++;
        return cmd;
    }

    // =================

    public List<String> getActions() {
        return actions;
    }

    public void setActions(List<String> actions) {
        this.actions = actions;
    }

    public int getActionMode() {
        return actionMode;
    }

    public void setActionMode(int actionMode) {
        this.actionMode = actionMode;
    }

    public int getActionCounter() {
        return actionCounter;
    }

    public void setActionCounter(int actionCounter) {
        this.actionCounter = actionCounter;
    }
}
